<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>
<!--  批量添加部门 -->
<html>
	<head>
		<base target="_self">
		<title>批量添加部门</title>
		<link href="<%=path%>/css/index_css.css" rel="stylesheet"
			type="text/css" />
		<script src="<%=path%>/dwr/engine.js"></script>
		<script src="<%=path%>/dwr/util.js"></script>
		<script src="<%=path%>/dwr/interface/shiyueDwr.js"></script>
		<script language="javascript" src="<%=path%>/js/validate.js"></script>
		<script language="javascript" src="<%=path%>/js/syAjax.js"></script>
		<script language="javascript" src="<%=path %>/js/jquery.js"></script>
		<script language="javascript">
		var objectHIDDENID;
		var objectTd;
		function doSubmit() {
			var organizationIds = document.getElementsByName('organizationIds');
			var names =document.getElementsByName("names");
			var sort=document.getElementsByName("sorts");
			if(organizationIds.length>0)
			{
				for(var i=0;i<organizationIds.length;i++)
				{
					if(organizationIds[i].value=='')
					{
						alert('部门编号不能为空！');
						return;
					}
				}
				for(var i=0;i<organizationIds.length;i++) {
					var img = organizationIds[i].parentNode.nextSibling.children[0];
					if(img && img.src.match('icon_11.gif')!=null) {
						alert(organizationIds[i].value+"此部门编号已存在！");
						return;
					}
				}
			}
			
			if (names.length>0){
				for(var i=0;i<names.length;i++)
				{
					if(names[i].value=="")
					{
						alert("部门名称不能为空！");
						return;
					}
				}
			}
			if(sort!="")
			{
				for(var i=0;i<sort.length;i++)
				{
					if(!/^-?[\d]{0,9}$/.test(sort[i].value))
					{
						alert('序号不能为空，且只能为数字！');
						return;
					}
				}
			}
			
		
		
			
			$.post('<%=path%>/batchAddorganizationAction.action',
			$('#batchForm').serialize() , function(data){
					parent.refreshJsp();	
			});
			
		}
		
	</script>
		<!--  页面 下拉框的动态加载 -->
		<script type="text/javascript">
		
		function giveParamArr(){
	  	return document.getElementById(objectHIDDENID).value;
	}
    
    //动态生成表格
    function doGenerate()
    {
    	document.getElementById("mark").innerHTML="";
    	var num=document.getElementById("num").value;//数量
    	var start=document.getElementById("start").value;
    	var innerHTMLV="<table width='100%' border='1' cellspacing='0' cellpadding='0'>";
    	for(var i=num;i>0;i--)
    	{
        	innerHTMLV+="<tr><td width='18%' bgcolor='#FFFFFF' align='left'><input type='text' name='code' value='' style='display:none;' disabled='disabled' size='4' /><input type='text' style='width:80px' name='organizationIds' onblur='checkID(this)' maxlength='20'/></td ><td width='4%' bgcolor='#FFFFFF' align='center'>&nbsp;</td><td width='33%' bgcolor='#FFFFFF' align='center' ><input type='text' style='width:200px' name='names' maxlength='25'/></td><td width='30%' bgcolor='#FFFFFF' align='center'><div style='border:1px;border-style:dotted; background-color: #FFFFFF;width: 200px;overflow:auto' onclick='choseUser(this,\"chairmens"+i+"\");' class='border_3'   style='cursor:pointer;' >点击此处设置部门负责人</div><input type='hidden' name='chairmens' id='chairmens"+i+"' value=''></td><td width='15%' align='center' bgcolor='#FFFFFF'><input type='text' value='"+start+"' style='width:50px' name='sorts'/></td></tr>";
        	start++;
        }
        innerHTMLV+="</table>";
    	document.getElementById("mark").innerHTML=innerHTMLV;
    	document.getElementById("dosub").innerHTML="<input type='button' name='Submit' value='提 交' onClick='doSubmit()'>";
    }
    
      function choseUser(obj,nameId){
        objectHIDDENID=nameId;
		objectTd=obj;
	  if('${applicationScope.currentYear}'==null || '${applicationScope.currentYear}'==""){
		alert("未设置当前年度，请先设置！");
		return;
	   }
	   var paramArr="";
	   var userId =obj.getElementsByTagName("input")[0];
	   
       var url="<%=path%>/toSelectTeacherorganizationAction.action?years=${applicationScope.currentYear}&role.roleId=bmfzr&paramArr="
       if(userId) {
       		url+=userId.value;
       }
       url+=",&actionURL=&t="+new Date();
       	parent.displayModuleDiv(url);
	   //var returnStr=window.showModalDialog(url,"","dialogHeight:600px;dialogWidth:800px;help=0;scroll=1;");
		//if(returnStr==undefined){
			//return;
		//}
		//if(returnStr!=null && returnStr!=""){
			//var UserArr = returnStr.substring(0,returnStr.length-1).split(",");
			//var UserNameStr="";
			//var nameStr='';
			//var idStr='';
				//for(var i=0;i<UserArr.length;i++){
					//var user=UserArr[i];
					//var sonArr=user.split("_");
					 //if(nameStr=='') {
					 	//nameStr=sonArr[1];
					 	//idStr=sonArr[0];
					 //}else{
					 	//nameStr += ','+sonArr[1];
					 	//idStr += ','+sonArr[0];
					// }
				//}
				//UserNameStr = nameStr+'<input type="hidden" name="chairmens" value="'+idStr+'" />';
				//if(UserNameStr!=""){									
					//obj.innerHTML=UserNameStr;					
				//}	
		//}
		//else
		//{
			//obj.innerHTML="点击此处设置部门负责人<input type='hidden' name='chairmens' value=''>";
		//}
    }
    
     function doChooseUser(returnStr){
    	if(returnStr==undefined){
			return;
		}
		if(returnStr!=null && returnStr!=""){
			var UserArr = returnStr.substring(0,returnStr.length-1).split(",");
			var UserNameStr="";
			var nameStr='';
			var idStr='';
				for(var i=0;i<UserArr.length;i++){
					var user=UserArr[i];
					var sonArr=user.split("_");
					 if(nameStr=='') {
					 	nameStr=sonArr[1];
					 }else{
					 	nameStr +=","+ sonArr[1];
					 }
					idStr += sonArr[0]+",";
				}
				UserNameStr = nameStr;
				document.getElementById(objectHIDDENID).value=idStr;
				if(UserNameStr!=""){
					objectTd.innerHTML=UserNameStr;					
				}	
		}else{
			objectTd.innerHTML="点击此处设置部门负责人";
		}
    
    }
    //检查ID
   		function checkID(obj)
      {
      		var callBackObj={type:'plain'};
      		callBackObj.success = function(resp) {
      			if(resp=='true' && obj.value!='' && $(':text[name="organizationIds"][value="'+obj.value+'"]').length==1) {
      				obj.parentNode.nextSibling.innerHTML='<img src="<%=path%>/images/icon_81.gif" border="0"/>';
      			}else {
      				obj.parentNode.nextSibling.innerHTML='<img src="<%=path%>/images/icon_11.gif" border="0"/>';
      			}
      			
      		};
         	
        	syAjax.request("post","<%=path %>/checkIDorganizationAction.action","organization.organizationId="+obj.value, callBackObj);
      }
</script>
	</head>
	<body >
		<form action="batchAddorganizationAction.action" method="post" id='batchForm'>
			<input type="hidden" name="organization.orgType" value="2" id="type" />
			<table width="700" border="0" align="center" cellpadding="0"
				cellspacing="0">
				<tr>
					<td height="38" align="center" valign="bottom" bgcolor="#ffffff"><font size="+1">批量添加部门</font>
					</td>
				</tr>
				<tr>
					<td align="center" valign="top" bgcolor="#ffffff">
						<table width="95%" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td height="1" bgcolor="#ABA899"></td>
							</tr>
							<tr>
								<td height="1" bgcolor="#FFFFFF"></td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td align="left" valign="top" bgcolor="#ffffff">
						<table width="100%" border="0" cellspacing="0" cellpadding="0"
							height="157">
							<tr>
							  <td height="30" align="right" class="f_6" width="24%">一次性添加几个部门：</td>
							  <td align="left"><select id="num" name="select">
                                <option value="1">1</option>
                                <option value="2">2</option>
                                <option value="3">3</option>
                                <option value="4">4</option>
                                <option value="5">5</option>
                                <option value="6">6</option>
                                <option value="7">7</option>
                                <option value="8">8</option>
                                <option value="9">9</option>
                                <option value="10">10</option>
                                <option value="11">11</option>
                                <option value="12">12</option>
                                <option value="13">13</option>
                                <option value="14">14</option>
                                <option value="15">15</option>
                                <option value="16">16</option>
                                <option value="17">17</option>
                                <option value="18">18</option>
                                <option value="19">19</option>
                                <option value="20">20</option>
                              </select></td>
						  </tr>
							<tr>
								<td height="30" align="right" class="f_6" width="24%">序号从第几个开始：</td>
								<td align="left"><select id="start" name="select2">
								  <option value="0">0</option>
                                  <option value="1">1</option>
                                  <option value="2">2</option>
                                  <option value="3">3</option>
                                  <option value="4">4</option>
                                  <option value="5">5</option>
                                  <option value="6">6</option>
                                  <option value="7">7</option>
                                  <option value="8">8</option>
                                  <option value="9">9</option>
                                  <option value="10">10</option>
                                  <option value="11">11</option>
                                  <option value="12">12</option>
                                  <option value="13">13</option>
                                  <option value="14">14</option>
                                  <option value="15">15</option>
                                  <option value="16">16</option>
                                  <option value="17">17</option>
                                  <option value="18">18</option>
                                  <option value="19">19</option>
                                  <option value="20">20</option>
                                </select></td>
							</tr>

							<tr>
								<td colspan="2" align="center">
									<table width="95%" border="0" cellspacing="0" cellpadding="0">
										<tr>
											<td height="1" bgcolor="#ABA899"></td>
										</tr>
										<tr>
											<td height="1" bgcolor="#FFFFFF"></td>
										</tr>
									</table>								</td>
							</tr>
							<tr>
								<td height="30" align="center">&nbsp;</td>
								<td align="left"><input type="button" name="Submit" value="下一步"
										onClick="doGenerate();" /></td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td align="center" valign="top" bgcolor="#ECE9D8">
						<table width="100%" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td height="1" bgcolor="#ABA899"></td>
							</tr>
							<tr>
								<td height="1" bgcolor="#FFFFFF"></td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
				<td align="left" valign="top" width="100%">
				<table width="100%" border="0" cellspacing="0" cellpadding="0">
				<tr height="25">
				<td width="22%" align="center" bgcolor="#C1D9F3" colspan="2">编号</td>
				<td width="33%" align="center" bgcolor="#C1D9F3">部门名称</td>
				<td width="30%" align="center" bgcolor="#C1D9F3">部门负责人</td>
				<td width="15%" align="center" bgcolor="#C1D9F3">序号</td>
				</tr>
				<tr>
				  <td colspan="5" width="100%">
				  	<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#C1D9F3">
				  		<tr>
				  			<td><span id="mark"></span></td>
				  		</tr>
				  	</table>
				  </td>
				  
				</tr>
				<tr>
				  <td colspan="2" align='center' ><span id="dosub"></span>
				  </td>
				</tr>
				</table>
				</td>
				</tr>
			</table>
		</form>
	</body>
</html>